package cn.zut.edu.dao;

import cn.zut.edu.model.Student;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;


import java.util.List;

@Repository(value = "bdi1")
public class StudentDaoImpl extends AbstractStudentDao {

    @Override
    public void insertStudent(Student student) {
        String INSERT_STUDENT="INSERT INTO student(id,name,gender,score) VALUES(?,?,?,?)";
        Object[] args={student.getId(),student.getName(),student.getGender(),student.getScore()};
        jdbcTemplate.update(INSERT_STUDENT,args);
    }

    @Override
    public List<Student> queryAll() {
        String QUERY_ALL_STUDENT="select * from student";
        RowMapper<Student> rowMapper=new BeanPropertyRowMapper<>(Student.class);
        students=jdbcTemplate.query(QUERY_ALL_STUDENT,rowMapper);
        return students;
    }


}
